package com.echo.im.storage.backup.mq;


import cn.hutool.core.bean.BeanUtil;
import com.echo.im.common.vo.message.PrivateMessageVO;
import com.echo.im.mq.contant.QueueConstants;
import com.echo.im.mq.event.receiver.AbstractMessageReceiver;
import com.echo.im.repository.dao.entity.PrivateMessage;
import com.echo.im.repository.dao.mapper.PrivateMessageMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 私聊消息存储队列消费者
 * @author echo
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class PrivateStorageMessageReceiver extends AbstractMessageReceiver<PrivateMessageVO> {

    private final PrivateMessageMapper privateMessageMapper;

    @Override
    public void doReceive(PrivateMessageVO data) {
        PrivateMessage privateMessage = BeanUtil.copyProperties(data, PrivateMessage.class);
        privateMessageMapper.insert(privateMessage);
    }

    @Override
    public String getQueueName() {
        return QueueConstants.STORE_PRIVATE_QUEUE;
    }
}
